package com.pri.chat.activity;

import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.flyco.tablayout.SlidingTabLayout;
import com.flyco.tablayout.listener.OnTabSelectListener;
import com.netease.nim.uikit.net.StatusBarUtil;
import com.pri.chat.R;
import com.pri.chat.base.BaseActivity;
import com.pri.chat.fragment.WishAllFragment;
import com.vondear.rxtool.RxActivityTool;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 描述：添加类的描述
 *
 * @author
 * @time 2020/4/27
 */
public class WishActivity extends AppCompatActivity {
    @BindView(R.id.rl_center)
    RelativeLayout rlCenter;
    @BindView(R.id.vp_wish)
    ViewPager vpWish;
    @BindView(R.id.iv_return)
    ImageView ivBack;
    @BindView(R.id.iv_release)
    ImageView ivRelease;
    @BindView(R.id.stl_wish)
    SlidingTabLayout stlWish;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_wish_layout);
        View view = findViewById(R.id.rl_center);
        StatusBarUtil.setColor(this, getResources().getColor(R.color.white), 0);
        StatusBarUtil.setTranslucentForImageViewInFragment(this, 0, view);
        StatusBarUtil.setLightMode(this);
        ButterKnife.bind(this);
        initView();
    }

    private String[] mTitle = new String[]{"未实现", "已实现"};


    private int selectIndex = 0;
    private ArrayList<Fragment> arrayList = new ArrayList<>();
    private void initView() {
        arrayList.add(WishAllFragment.getInstance(1));
        arrayList.add(WishAllFragment.getInstance(2));
        stlWish.setViewPager(vpWish, mTitle, this, arrayList);
        stlWish.getTitleView(0).setTextSize(20);
        stlWish.getTitleView(1).setTextSize(14);
        stlWish.setOnTabSelectListener(new OnTabSelectListener() {
            @Override
            public void onTabSelect(int position) {
                selectIndex = position;
                for (int i = 0; i < arrayList.size(); i++) {
                    if (i == position) {
                        stlWish.getTitleView(position).setTextSize(20);
                        stlWish.getTitleView(position).setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
                    } else {
                        stlWish.getTitleView(i).setTextSize(14);
                        stlWish.getTitleView(i).setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
                    }
                }

            }

            @Override
            public void onTabReselect(int position) {

            }
        });
        vpWish.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                selectIndex = position;
                for (int i = 0; i < arrayList.size(); i++) {
                    if (i == position) {
                        stlWish.getTitleView(position).setTextSize(20);
                        stlWish.getTitleView(position).setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
                    } else {
                        stlWish.getTitleView(i).setTextSize(14);
                        stlWish.getTitleView(i).setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
                    }
                }
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
        stlWish.getTitleView(selectIndex).setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
    }


    @OnClick({R.id.iv_return, R.id.iv_release})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_return:
                finish();
                break;
            case R.id.iv_release:
                RxActivityTool.skipActivity(this, ReleaseWishAcctivity.class);
                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(resultCode == RESULT_OK){
            if(requestCode == 1){
                arrayList.get(0).onActivityResult(10,resultCode,data);
            }
        }
    }
}
